﻿
// 获取当前日期时间
var now = new Date();
var year = now.getFullYear();
var month = ("0" + (now.getMonth() + 1)).slice(-2);
var day = ("0" + now.getDate()).slice(-2);
var hours = ("0" + now.getHours()).slice(-2);
var minutes = ("0" + now.getMinutes()).slice(-2);
//var seconds = ("0" + now.getSeconds()).slice(-2);
var serialNumber = "CG" + year + month + day + hours + minutes;
var inputElement = document.getElementById('purchaseCode');
inputElement.value = serialNumber;
var serialNumber1 = "PX" + year + month + day + hours;
var inputElement1 = document.getElementById('purchaseBatch');
inputElement1.value = serialNumber1;

var obj1 = {
    "createdBy": "",
    "createdDate": "",
    "updatedBy": "",
    "updatedDate": "",
    "deletedBy": "",
    "deletedDate": "",
    "isDeleted": false,
    "purchaseID": "",
    "purchaseCode": "",
    "ingredientnumber": "",
    "ingredientName": "",
    "purchaseNumber": "",
    "purchaseSpecification": "",
    "purchaseSize": "",
    "purchaseDate": "",
    "purchaseBudget": "",
    "purchaseBatch": "",
    "purchaseSart": "",
    "purchaseSumMoney": "",
    "purchasePrice": "",
    "purchasePayPrice": "",
    "payType": "",
    InventoryState:""
};

layui.use(['table', 'dropdown', 'layer', 'form'], function () {
    var table = layui.table;
    var dropdown = layui.dropdown;
    var layer = layui.layer;
    var form = layui.form;
    var laypage = layui.laypage;
   
    //添加采购信息
    form.on('submit(formSubmit)', function (data) {
        var field = data.field;
        var checkStatus = table.checkStatus('allocationPurch');
        field.allocationProdutesList = checkStatus.data.map(function (item) {
            return item;
        });
        console.log(field);//field.products
      
        obj1.purchaseCode = $("#purchaseCode").val()
        obj1.ingredientnumber = $("#ingredient").val()
        obj1.ingredientName = $("#ingredientName").val()
        obj1.purchaseNumber = $("#purchaseNumber").val()
        obj1.purchaseSpecification = $("#purchaseSpecification").val()
        obj1.purchaseSize = $("#purchaseSize").val()
        obj1.purchaseDate = $("#purchaseDate").val()
        obj1.purchaseBudget = $("#purchaseBudget").val()
        obj1.purchaseBatch = $("#purchaseBatch").val()
        obj1.purchaseSart = "待采购"
        obj1.InventoryState="待入库"
        console.log(obj1)
        // 显示填写结果，仅作演示用
        $.ajax({
            url: '../Purch/GetPurchAdd',
            type: 'post',
            data: {
                field: obj1, token: localStorage.getItem("token")
            },
            success: function (res) {
                var res = JSON.parse(res)
                console.log(field);
                console.log(res);
                if (res.code > 0) {
                    layer.alert("添加成功");
                    location.href = '/Purch/ShowPurch'
                } else {
                    layer.alert("添加失败");
                }
            }
        });

        return false; // 阻止默认 form 跳转
    });

})
